package com.lrs.java.jdbc.jdbc_teacher;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
//插入
class TestInsertEmp2 {
	public static void main(String[] args) {
		if (args.length != 7) {
			System.out.println("args length error!");
			System.exit(-1);
		}

		String strEmpNo = args[0];
		int empno = -1;
		try {
			empno = Integer.parseInt(strEmpNo);
		} catch (NumberFormatException e1) {
			System.out.println("empno error");
			e1.printStackTrace();
			System.exit(-1);
		}

		String ename = args[1];
		String job = args[2];
		int mgr = Integer.parseInt(args[3]);
		double sal = Double.parseDouble(args[4]);
		double comm = Double.parseDouble(args[5]);
		int deptno = Integer.parseInt(args[6]);

		Connection conn = null;
		Statement stmt = null;

		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@192.168.0.1:1521:SXTBJ", "scott",
					"tiger");
			stmt = conn.createStatement();

			String sql = "insert into emp2 values (" + empno + ","
												     + "'" + ename + "',"
												     + "'" + job + "',"
												     + mgr + ",sysdate,"
												     + sal + ","
												     + comm + ","
												     + deptno + ")";
			//打印调试信息出来
			System.out.println(sql);
			stmt.executeUpdate(sql);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (stmt != null) {
					stmt.close();
					stmt = null;
				}
				if (conn != null) {
					conn.close();
					conn = null;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
